//
//  UIButton+Extension.swift
//  微博
//
//  Created by mac on 15/12/17.
//  Copyright © 2015年 mac. All rights reserved.
//

import UIKit

//便利构造方法
extension UIButton {
    
    convenience init(title:String,imageName:String? = nil,color:UIColor,fontSize:CGFloat,backImageName:String? = nil) {
        self.init()
        setTitleColor(color, forState: .Normal)
        if backImageName != nil {
            setBackgroundImage(UIImage(named: backImageName!), forState: .Normal)
        }
        if imageName != nil {
            setImage(UIImage(named: imageName!), forState: .Normal)
        }
        setTitle(title, forState: .Normal)
        contentMode = UIViewContentMode.Center
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        sizeToFit()
    }
    
    convenience init(imageName:String?,backImageName:String) {
        self.init()
        if imageName != nil{
        setImage(UIImage(named: imageName!), forState:.Normal)
            setImage(UIImage(named: imageName! + "_highlighted"), forState:.Highlighted)
        }
        setBackgroundImage(UIImage(named: backImageName), forState:.Normal)
        setBackgroundImage(UIImage(named: backImageName + "_highlighted"), forState:.Highlighted)
        sizeToFit()
    }
    
    
    
    
}


